<html>
<head>
<title>Search Book</title>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>

</head>
<body>
<h1>Search Book Result</h1>
<br/>
<?php

    $username="bsc353_4";
    $password="sonbeans";
    $database="bsc353_4";

    $ISBN=$_POST['ISBN'];
    $title=$_POST['title'];
    $author=$_POST['author'];
    $subject=$_POST['subject'];
    $publisher=$_POST['publisher'];

    mysql_connect("clipper.encs.concordia.ca",$username,$password);

    @mysql_select_db($database) or die ("Unable to select database");

    $query="SELECT * FROM Book WHERE ";
    $first = TRUE;
    if ($ISBN != '')
    {
       $query .= "ISBN = '$ISBN'";
       $first = FALSE;
    }

    if ($title != '')
    {
        if ($first == FALSE)
            $query .= " AND ";

        $query .= "title LIKE '%{$title}%'";
        $first = FALSE;
    }
    if ($author != '')
    {
        if ($first == FALSE)
            $query .= " AND ";
        $query .= "author LIKE '%{$author}%' OR author LIKE '%{$author}' OR author LIKE '{$author}%' ";
        $first = FALSE;
    }
    if ($subject != '')
    {
        if ($first == FALSE)
            $query .= " AND ";
        $query .= "subject = '$subject'";
        $first = FALSE;
    }
    if ($publisher != '')
    {
        if ($first == FALSE)
            $query .= " AND ";
        $query .= "publisher = '{$publisher}' OR publisher LIKE '%{$publisher}' OR publisher LIKE '{$publisher}%' ";
        $first = FALSE;
    }

    $query .= ";";
        
    $result=mysql_query($query) or die ("No Results");
    
$num=mysql_numrows($result);

mysql_close();
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<td><font face="Arial, Helvetica, sans-serif">ISBN</font></td>
<td><font face="Arial, Helvetica, sans-serif">Title</font></td>
<td><font face="Arial, Helvetica, sans-serif">Year</font></td>
<td><font face="Arial, Helvetica, sans-serif">Subject</font></td>
<td><font face="Arial, Helvetica, sans-serif">Author</font></td>
<td><font face="Arial, Helvetica, sans-serif">Publisher</font></td>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"ISBN");
$f2=mysql_result($result,$i,"title");
$f3=mysql_result($result,$i,"year");
$f4=mysql_result($result,$i,"subject");
$f5=mysql_result($result,$i,"author");
$f6=mysql_result($result,$i,"publisher");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f6; ?></font></td>
</tr>

<?php
$i++;
}
?>

</body>
</html>
